package com.ay.wiki_plt.mapper;

import com.ay.wiki_plt.domain.Doc;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface DocMapper {
    /*查询全部文档*/
    @Select("select * from doc where ebook_id = #{ebookId}")
    List<Doc> list(Long ebookId);


    /*根据id查询文档*/
    @Select("select * from doc where id = #{id}")
    Doc listOne(Long id);


    /*查询全部文档 分页*/
    List<Doc> page(String name);

    /*保存文档*/
    @Insert("insert into doc(id, ebook_id, parent, name, sort, view_count, vote_count) " +
            "VALUES (#{id},#{ebookId}, #{parent}, #{name}, #{sort}, #{viewCount}, #{voteCount})")
    void insertDoc(Doc doc);

    /*修改文档*/
    void updateDoc(Doc doc);

    /*批量删除文档*/
    void deleteBatchIds(List<Long> ids);

    /*查询全部文档*/
    @Select("select * from doc")
    List<Doc> getDocList();

    /*更新文档阅读数*/
    void updateDocView(Long id);

    /*点赞功能*/
    @Update("update doc set vote_count = vote_count + 1 where id = #{id}")
    void vote(Long id);

    //定时更新电子书
    void updateEbookInfo();
}
